var t = require("../../../../@babel/runtime/helpers/interopRequireDefault"), o = require("../../../../@babel/runtime/helpers/defineProperty"), a = t(require("../../../../@babel/runtime/regenerator")), s = require("../../../../@babel/runtime/helpers/asyncToGenerator"), i = getApp();

Component({
    properties: {
        goodsInfo: {
            type: null
        },
        goods_plugin: {
            type: null
        },
        isRent: {
            type: null
        },
        goodsId: {
            type: null
        },
        goodsType: {
            type: null
        },
        mark: {
            type: null
        },
        mode: {
            type: null
        },
        vieText: {
            type: null
        },
        fromStock: {
            type: String || Number
        },
        store_id: {
            type: String || Number
        },
        coid: {
            type: null
        },
        debtId: {
            type: null
        }
    },
    data: {
        showSkuImages: !1,
        skuImages: !1,
        activeSkuIndex: 0,
        activeSkuIndex_1: null,
        activeSkuIndex_2: null,
        integral: "积分",
        popupSpecs: !1,
        SUBMIT_ACTION_CART: "-1",
        SUBMIT_ACTION_BUY: "-2",
        groupModel: "",
        specsManage: [],
        optionsId: "",
        goodsCount: 1,
        goodsDescription: "",
        popStock: 0,
        popPrice: 0,
        popThumb: "",
        optionsMaxCount: 1,
        submitActionTag: "-2",
        gooddatas: [],
        activityId: "",
        isAward: "",
        language: "",
        buyType: 0,
        levelModel: 0,
        give_integral_count: "",
        isMultiSpecs: !1,
        specsVIPPrc: null
    },
    observers: {
        "popupSpecs,popupSpecs2,goodsInfo,goodsType": function(t, o, a, s) {
            "grabGroup" == s && this.setData({
                gooddatas: a
            }), t && (console.log("有没有规格id", this.data.optionsId), this.data.optionsId || this.firstArr());
        }
    },
    lifetimes: {
        attached: function() {
            var t = wx.getStorageSync("langIndex"), o = wx.getStorageSync("yz_basic_info");
            this.setData({
                language: t.en,
                vip_show: !!o.globalParameter.vip_show && o.globalParameter.vip_show
            });
            var a = wx.getStorageSync("integral");
            a && this.setData({
                integral: a
            });
        }
    },
    methods: {
        setMrSpec: function() {
            var t = this;
            return new Promise(function(o, a) {
                for (var s = 0; s < t.data.goodsInfo.has_many_options.length; s++) t.data.goodsInfo.has_many_options[s].id == t.data.coid && o(t.data.goodsInfo.has_many_options[s].specs);
            });
        },
        firstArr: function() {
            var t = this;
            return s(a.default.mark(function o() {
                var s, i, e, n;
                return a.default.wrap(function(o) {
                    for (;;) switch (o.prev = o.next) {
                      case 0:
                        if (s = t, !t.data.coid) {
                            o.next = 6;
                            break;
                        }
                        return o.next = 4, t.setMrSpec();

                      case 4:
                        i = (i = o.sent).split("_");

                      case 6:
                        if (1 == t.data.goodsInfo.has_option) for (e = 0; e < s.data.goodsInfo.has_many_specs.length; e++) if (t.data.coid) for (n = 0; n < t.data.goodsInfo.has_many_specs[e].specitem.length; n++) console.log(t.data.goodsInfo.has_many_specs[e].specitem[n].id, Number(t.data.coid), "sssss"), 
                        t.data.goodsInfo.has_many_specs[e].specitem[n].id == Number(i[e]) && t.selectSpecs(t.data.goodsInfo.has_many_specs[e].specitem[n], "first", e); else s.data.goodsInfo.has_many_specs[e].description = s.data.goodsInfo.has_many_specs[e].specitem[0].id, 
                        s.selectSpecs(s.data.goodsInfo.has_many_specs[e].specitem[0], "first", e);
                        0 != t.data.goodsInfo.has_option || "group_goods" != t.data.goodsType && "ywmGroup" != t.data.goodsType || t.selectGroup();

                      case 8:
                      case "end":
                        return o.stop();
                    }
                }, o);
            }))();
        },
        popupSpecsbtn: function() {
            this.setData({
                popupSpecs: !1,
                popupModeshow: !0
            }), this.triggerEvent("popupModeshowChild", !0), this.triggerEvent("paramsOptionsId", {
                option: this.data.optionsId,
                goodsCount: this.data.goodsCount
            });
        },
        getOptionsMaxCount: function(t) {
            var o = this.data.goods_plugin;
            if (o && o.month_buy_limit && o.month_buy_limit != [] && o.month_buy_limit.hasOwnProperty("limit")) {
                var a = o.month_buy_limit, s = a.limit, i = a.member_purchased, e = Number(s) - Number(i);
                return e > 0 ? e : 1;
            }
            return t;
        },
        addGoods: function() {
            if ("grabGroup" != this.data.goodsType) {
                var t = this.data.goodsCount, o = this.data.specsManage, a = this.getOptionsMaxCount(this.data.goodsInfo.stock);
                if (o.length == this.data.goodsInfo.has_many_specs.length && this.data.goodsCount == a) return wx.showToast({
                    icon: "none",
                    title: "最多购买".concat(a, "件"),
                    duration: 2500
                }), void console.log("max=" + this.data.goodsCount);
                this.setData({
                    goodsCount: t + 1
                });
            }
        },
        reduceGoods: function() {
            if ("grabGroup" != this.data.goodsType) {
                var t = this.data.goodsCount;
                1 != this.data.goodsCount && 0 != this.data.goodsCount && this.setData({
                    goodsCount: t - 1
                });
            }
        },
        showSkuImages_Methob: function() {
            this.triggerEvent("popupModeshowChild", !0), console.log(this.data.skuImages), this.setData({
                popupSpecs: !1,
                popupSpecs2: !1,
                showSkuImages: !0
            }), 1 == this.data.goodsInfo.has_option && this.setData({
                activeSkuIndex_1: this.data.goodsInfo.has_many_options[this.data.activeSkuIndex].specs
            });
        },
        onChangeSkuImagesIndex: function(t) {
            var o = t.detail.current;
            this.setData({
                activeSkuIndex: o
            }), 1 == this.data.goodsInfo.has_option && this.setData({
                activeSkuIndex_2: this.data.goodsInfo.has_many_options[o].specs
            });
        },
        onCloseSkuImages: function() {
            if (console.log(this.data.goodsInfo), 1 != this.data.goodsInfo.has_option) return this.setData({
                popupSpecs2: !0,
                popupModeshow: !1,
                showSkuImages: !1
            }), void this.triggerEvent("popupModeshowChild", !1);
            var t = this.data.activeSkuIndex_1.split("_"), o = this.data.goodsInfo, a = this.data.activeSkuIndex;
            if (this.data.activeSkuIndex_1 != this.data.goodsInfo.has_many_options[a].specs) for (var s = this.data.activeSkuIndex_2.split("_"), e = 0; e < t.length; e++) if (t[e] != s[e]) for (var n = Number(s[e]), d = 0; d < this.data.goodsInfo.has_many_specs.length; d++) for (var p = 0; p < this.data.goodsInfo.has_many_specs[d].specitem.length; p++) this.data.goodsInfo.has_many_specs[d].specitem[p].id == n && (o.has_many_specs[d].description = this.data.goodsInfo.has_many_specs[d].specitem[p].id);
            var r = "";
            r = this.data.goods_plugin.point_goods ? this.data.goods_plugin.point_goods.point_option[a].goods_point : this.data.goodsInfo.has_many_options[a].product_price, 
            this.triggerEvent("popupModeshowChild", !1), this.setData({
                goodsInfo: o,
                showSkuImages: !1,
                popupSpecs: !0,
                popupModeshow: !1,
                popPrice: r,
                popThumb: i._isTextEmpty(this.data.goodsInfo.has_many_options[a].thumb) ? this.data.goodsInfo.thumb : this.data.goodsInfo.has_many_options[a].thumb,
                popStock: this.data.goodsInfo.has_many_options[a].stock,
                optionsId: this.data.goodsInfo.has_many_options[a].id
            });
        },
        initPopView: function() {
            var t = this, o = "";
            if (1 == this.data.goodsInfo.has_option) {
                o = this.data.goods_plugin.point_goods ? this.data.goods_plugin.point_goods.min_point + "-" + this.data.goods_plugin.point_goods.max_point : this.data.goodsInfo.min_price + "-" + this.data.goodsInfo.max_price, 
                this.setData({
                    popPrice: o,
                    popThumb: this.data.goodsInfo.thumb,
                    popStock: this.data.goodsInfo.stock,
                    goodsDescription: "选择"
                });
                for (var a = 0; a < this.data.goodsInfo.has_many_specs.length; a++) this.setData({
                    goodsDescription: this.data.goodsDescription + " " + this.data.goodsInfo.has_many_specs[a].title
                });
                var s = [];
                this.data.goodsInfo.has_many_options.forEach(function(o, a) {
                    var i = "" != o.thumb ? o.thumb : t.data.goodsInfo.thumb;
                    s.push(i);
                }), this.setData({
                    skuImages: s
                });
            } else {
                var i = [];
                i.push(this.data.goodsInfo.thumb), o = this.data.goods_plugin.point_goods ? this.data.goods_plugin.point_goods.point : this.data.goodsInfo.price, 
                this.setData({
                    popThumb: this.data.goodsInfo.thumb,
                    popStock: this.data.goodsInfo.stock,
                    popPrice: o,
                    goodsDescription: "",
                    optionsMaxCount: this.data.goodsInfo.stock,
                    skuImages: i
                });
            }
        },
        buyNowNew: function() {
            if (this.data.submitActionTag == this.data.SUBMIT_ACTION_CART) return this.setData({
                popupSpecs: !1
            }), this.triggerEvent("popupModeshowChild", !0), this.addCartRequest(this.data.goodsId, this.data.optionsId, this.data.goodsCount), 
            void this.hidePopView2();
            this.hidePopView2(), "retailGood" == this.data.goodsType ? this.buyNowRequestRetailGood(this.data.goodsId, this.data.optionsId, this.data.goodsCount) : "zhpGroup" == this.data.goodsType ? this.buyNowRequestZhpGroup(this.data.goodsId, this.data.optionsId, this.data.goodsCount) : this.buyNowRequest(this.data.goodsId, this.data.optionsId, this.data.goodsCount);
        },
        hidePopView2: function() {
            this.triggerEvent("popupModeshowChild", !0), this.setData({
                popupSpecs2: !1
            });
        },
        buyNowRequest: function(t, o, a) {
            if (0 != this.data.optionsMaxCount) if (a <= 0) wx.showToast({
                icon: "none",
                title: "请选择商品数量",
                duration: 2500
            }); else if (1 == this.data.goodsInfo.has_option && i._isTextEmpty(o)) wx.showToast({
                icon: "none",
                title: "请选择规格！",
                duration: 2500
            }); else {
                var s = this, e = [];
                e.push(t);
                var n = i.getNetAddresss("from.div-from.isDisplay");
                n += "&goods_ids=" + JSON.stringify(e), i._getNetWork({
                    showToastIn: !1,
                    url: n,
                    success: function(e) {
                        var n = e.data;
                        if (1 == n.result) if (n.data.status && !n.data.member_status) wx.showModal({
                            title: "提示",
                            content: "购买此商品,请补充您的个人信息",
                            success: function(t) {
                                t.confirm ? wx.navigateTo({
                                    url: "/packageB/member/address/myinfo/myinfo?tag=delta"
                                }) : t.cancel && console.log("用户点击取消");
                            }
                        }); else {
                            var d = "/packageD/buy/myOrder_v2/myOrder_v2?goodsId=" + t + "&optionsId=" + o + "&total=" + a + "&tag=";
                            if (s.data.activityid) return void wx.navigateTo({
                                url: d + s.data.submitActionTag + "&activity_id=" + s.data.activityid
                            });
                            if (!i._isTextEmpty(s.data.debtId)) return void wx.navigateTo({
                                url: d + "&debtId=" + s.data.debtId
                            });
                            if ("appointment_goods" == s.data.goodsType) return void wx.navigateTo({
                                url: d + "appointment_goods"
                            });
                            if ("yunqian_api" == s.data.goodsType) return void wx.navigateTo({
                                url: d + "yunqian_api"
                            });
                            if ("store_projects_goods" == s.data.goodsType) return void wx.navigateTo({
                                url: d + "store_projects_goods"
                            });
                            if ("vending_machine" == s.data.mark) return void wx.navigateTo({
                                url: d + "machine&machineId=" + s.data.goods_plugin.automat.machine_id
                            });
                            s.data.isCup ? "POrder" == s.data.vieText ? wx.navigateTo({
                                url: d + "POrder"
                            }) : wx.navigateTo({
                                url: d + s.data.submitActionTag + "&fromStock=" + s.data.fromStock
                            }) : s.data.isRent ? wx.navigateTo({
                                url: d + "rentBuy&mark=" + s.data.mark
                            }) : (d = d + s.data.submitActionTag + "&mark=" + s.data.mark + "&fromStock=" + s.data.fromStock, 
                            wx.navigateTo({
                                url: d
                            }));
                        } else wx.showToast({
                            icon: "none",
                            title: n.msg,
                            duration: 2500
                        });
                    },
                    fail: function(t) {}
                });
            } else wx.showToast({
                icon: "none",
                title: "商品库存不足",
                duration: 2500
            });
        },
        submitAction: function() {
            if (this.data.specsManage.length < this.data.goodsInfo.has_many_specs.length) return this.setData({
                popupSpecs: !1
            }), this.triggerEvent("popupModeshowChild", !0), void wx.showToast({
                icon: "none",
                title: this.data.goodsDescription,
                duration: 2500
            });
            if (this.data.submitActionTag == this.data.SUBMIT_ACTION_CART) this.setData({
                popupSpecs: !1
            }), this.triggerEvent("popupModeshowChild", !0), this.addCartRequest(this.data.goodsId, this.data.optionsId, this.data.goodsCount); else if (this.data.submitActionTag == this.data.SUBMIT_ACTION_BUY) {
                if (this.setData({
                    popupSpecs: !1
                }), this.triggerEvent("popupModeshowChild", !0), "design" == this.data.submitTag) return void this.triggerEvent("paramsOptionsId", {
                    option: this.data.optionsId,
                    goodsCount: this.data.goodsCount
                });
                this.buyNowRequest(this.data.goodsId, this.data.optionsId, this.data.goodsCount);
            }
        },
        inputGoodsNum: function(t) {
            var o = parseInt(t.detail.value), a = this.data.goodsCount;
            8 == t.detail.keyCode && i._isTextEmpty(t.detail.value) ? this.setData({
                goodsCount: ""
            }) : o ? this.setData({
                goodsCount: o
            }) : this.setData({
                goodsCount: a
            });
        },
        selectSpecs: function(t, a, s) {
            var i = {}, e = 0;
            if ("first" == a ? (e = s, i = t) : "sku_swiper" == a ? i = t : (e = t.currentTarget.dataset.specsidex, 
            i = t.currentTarget.dataset.specitem), i.c) return !1;
            this.setData(o({}, "goodsInfo.has_many_specs[" + e + "].description", i.id)), this.isShowMultiSpecsMemPrice(), 
            this.manageSpecs(i), this.setGoodsSpecs(i), this.setGoodsSpecsChangeInfo(), this.data.goodsInfo.min_buy_num && this.setData({
                goodsCount: this.data.goodsInfo.min_buy_num
            }), this.getMaxCount(), this.triggerEvent("paramsOptionsId", {
                option: this.data.optionsId,
                goodsCount: this.data.goodsCount
            });
        },
        isShowMultiSpecsMemPrice: function() {
            -1 == [ "groupBuy", "grabGroup", "grabGroup", "group_goods", "retailGood", "starGroup", "zhpGroup", "ywmGroup" ].indexOf(this.data.goodsType) ? this.setData({
                isMultiSpecs: this.data.vip_show
            }) : this.setData({
                isMultiSpecs: !1
            });
        },
        manageSpecs: function(t) {
            var o = new Object(), a = this.data.specsManage;
            if (o.id = t.id, o.specid = t.specid, o.title = t.title, a.length > 0) {
                for (var s = 0; s < a.length; s++) a[s].specid == o.specid && a.splice(s, 1);
                a.push(o);
            } else a.push(o);
            if (a.length == this.data.goodsInfo.has_many_specs.length) {
                for (var i = [], e = 0; e < this.data.goodsInfo.has_many_specs.length; e++) for (var n = 0; n < a.length; n++) if (this.data.goodsInfo.has_many_specs[e].id == a[n].specid) {
                    i.push(a[n]);
                    break;
                }
                a = i;
            }
            this.setData({
                specsManage: a
            }), this.setGoodsDescription();
        },
        setGoodsDescription: function() {
            var t = "", o = this.data.specsManage;
            if (o.length == this.data.goodsInfo.has_many_specs.length) {
                t = "已选择 ";
                for (var a = 0; a < o.length; a++) t += o[a].title + " ";
                this.setData({
                    goodsDescription: t
                });
            } else {
                t = "请选择 ";
                for (var s = 0; s < this.data.goodsInfo.has_many_specs.length; s++) for (var i = 0; i < o.length; i++) if (this.data.goodsInfo.has_many_specs[s].id != o[i].specid) {
                    t += this.data.goodsInfo.has_many_specs[s].title + " ";
                    break;
                }
                this.setData({
                    goodsDescription: t
                });
            }
        },
        setGoodsSpecs: function(t) {
            for (var o = 0; o < this.data.goodsInfo.has_many_specs.length; o++) t.specid, this.data.goodsInfo.has_many_specs[o].id;
        },
        setGoodsSpecsChangeInfo: function() {
            var t = this.data.specsManage, o = "";
            if (t.sort(function(t, o) {
                return t.id - o.id;
            }), t.length == this.data.goodsInfo.has_many_specs.length) {
                for (var a = "", s = 0; s < t.length; s++) a += t[s].id + "_";
                a = a.substring(0, a.length - 1);
                for (var e = 0; e < this.data.goodsInfo.has_many_options.length; e++) if (a == this.setGoodsSpecsBySort(this.data.goodsInfo.has_many_options[e].specs)) {
                    o = this.data.goods_plugin.point_goods ? this.data.goods_plugin.point_goods.point_option[e].goods_point : this.data.goodsInfo.has_many_options[e].product_price, 
                    this.setData({
                        activeSkuIndex: e,
                        popPrice: o,
                        popThumb: i._isTextEmpty(this.data.goodsInfo.has_many_options[e].thumb) ? this.data.goodsInfo.thumb : this.data.goodsInfo.has_many_options[e].thumb,
                        popStock: this.data.goodsInfo.has_many_options[e].stock,
                        optionsId: this.data.goodsInfo.has_many_options[e].id,
                        give_integral_count: this.data.goodsInfo.has_many_options[e].points
                    }), this.data.optionsMaxCount = this.data.goodsInfo.has_many_options[e].stock, this.data.optionsMaxCount > 0 && this.setData({
                        goodsCount: 1
                    }), this.data.isMultiSpecs && this.getMemberPrice(this.data.optionsId), "group_goods" == this.data.goodsType || "ywmGroup" == this.data.goodsType ? (console.log(this.data.goodsType, "group_goods"), 
                    this.setGroupInfo(this.data.optionsId)) : this.setZhpGroupInfo(this.data.optionsId);
                    break;
                }
            }
            this.setData({
                specsManage: t
            });
        },
        setGoodsSpecsBySort: function(t) {
            var o = t.split("_");
            o.sort(function(t, o) {
                return t - o;
            });
            for (var a = "", s = 0; s < o.length; s++) a += o[s] + "_";
            return a = a.substring(0, a.length - 1);
        },
        getMaxCount: function() {
            var t = this.data.specsManage, o = this.data.optionsMaxCount;
            t.length == this.data.goodsInfo.has_many_specs.length && (0 == o && this.setData({
                goodsCount: 0
            }), this.data.goodsCount > o && this.setData({
                goodsCount: o
            }));
        },
        getMemberPrice: function(t) {
            var o = this;
            if (t) {
                var a = 0;
                this.setData({
                    specsVIPPrc: a
                });
                var s = i.getNetAddresss("goods.other-info.option-vpi-price");
                s += "&option_id=" + t, i._getNetWork({
                    showToastIn: !1,
                    url: s,
                    success: function(t) {
                        var s = t.data;
                        a = 1 == s.result && s.data.vip_price || null, o.setData({
                            specsVIPPrc: a
                        });
                    },
                    fail: function(t) {
                        a = null, this.setData({
                            specsVIPPrc: a
                        });
                    }
                });
            }
        },
        addCartRequest: function(t, o, a) {
            if (0 != this.data.optionsMaxCount) {
                if (a <= 0) return this.setData({
                    popupSpecs: !1,
                    popupModeshow: !0
                }), void wx.showToast({
                    icon: "none",
                    title: "请选择商品数量",
                    duration: 2500
                });
                var s = this, e = [];
                e.push(t);
                var n = i.getNetAddresss("from.div-from.isDisplay");
                n += "&goods_ids=" + JSON.stringify(e), i._getNetWork({
                    showToastIn: !1,
                    url: n,
                    success: function(i) {
                        var e = i.data;
                        1 == e.result ? e.data.status && !e.data.member_status ? wx.showModal({
                            title: "提示",
                            content: "购买此商品,请补充您的个人信息",
                            success: function(t) {
                                t.confirm ? wx.navigateTo({
                                    url: "/packageB/member/address/myinfo/myinfo?tag=delta"
                                }) : t.cancel && console.log("用户点击取消");
                            }
                        }) : s.addCartReq(t, o, a) : wx.showToast({
                            icon: "none",
                            title: e.msg,
                            duration: 2500
                        });
                    },
                    fail: function(t) {}
                });
            } else wx.showToast({
                icon: "none",
                title: "商品库存不足",
                duration: 2500
            });
        },
        addCartReq: function(t, o, a) {
            var s = this, e = i.getNetAddresss("member.member-cart.store");
            e += "&goods_id=" + t, e += "&total=" + a, e += "&option_id=" + o, i._getNetWork({
                showToastIn: !1,
                url: e,
                success: function(t) {
                    var o = t.data;
                    1 == o.result ? (i.globalData.cart_num = o.data.cart_num, s.triggerEvent("changeCartNumber", o.data.cart_num), 
                    wx.showToast({
                        icon: "none",
                        title: o.msg,
                        duration: 2500
                    })) : wx.showModal({
                        title: "提示",
                        content: o.msg,
                        showCancel: !1,
                        success: function(t) {}
                    });
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        },
        selectGroup: function(t) {
            var o = this;
            if (t) {
                var a = t.target.dataset.item || t.currentTarget.dataset.item;
                this.setData({
                    groupModel: a.id
                });
            }
            this.data.groupModel || this.setData({
                groupModel: this.data.gooddatas.has_many_level[0].id
            });
            var s = [];
            if (!i._isTextEmpty(this.data.groupModel)) if (1 == this.data.goodsInfo.has_option) {
                if (i._isTextEmpty(this.data.optionsId) || 0 == this.data.optionsId) return wx.showToast({
                    title: "请选择商品规格！",
                    icon: "none",
                    duration: 2500
                }), void this.setData({
                    groupModel: ""
                });
                s = this.data.selectGroupInfo.filter(function(t) {
                    if (t.level_id == o.data.groupModel) return t.group_price;
                }), this.setData({
                    popPrice: s[0].group_price
                }), this.setData({
                    option_level_id: s[0].id
                });
            } else this.setData({
                selectGroupInfo: this.data.gooddatas.has_many_options[0].has_many_option_level,
                optionsMaxCount: 0 == this.data.gooddatas.has_many_options[0].buy_limit ? this.data.gooddatas.has_many_options[0].stock : this.data.gooddatas.has_many_options[0].buy_limit
            }), s = this.data.selectGroupInfo.filter(function(t) {
                if (t.level_id == o.data.groupModel) return t.group_price;
            }), this.setData({
                option_level_id: s[0].id,
                popPrice: s[0].group_price
            });
        },
        openCardGroup: function() {
            var t = this;
            wx.showModal({
                title: "提示",
                content: "确认开团",
                success: function(o) {
                    o.confirm ? t.confirmOpenCardGroup() : o.cancel && t.setData({
                        popupSpecs: !1,
                        popupSpecs2: !1
                    });
                }
            });
        },
        confirmOpenCardGroup: function() {
            var t = this, o = {
                member_open_group_id: this.data.gooddatas.member_open_card_id,
                group_id: this.data.gooddatas.id,
                goods: JSON.stringify([ {
                    goods_id: this.data.goodsId,
                    option_id: this.data.optionsId,
                    total: 1
                } ]),
                level_id: this.data.groupModel,
                option_level_id: this.data.option_level_id
            }, a = i.getNetAddresss("plugin.ywm-fight-groups.frontend.controllers.fight-groups.card-open-group");
            i._postNetWork({
                url: a,
                data: o,
                success: function(o) {
                    var a = o.data;
                    i.tips(a.msg), 1 == a.result && (t.setData({
                        popupSpecs: !1,
                        popupSpecs2: !1
                    }), t.triggerEvent("popupModeshowChild", !0), wx.redirectTo({
                        url: "/packageB/member/group/ywmGroupsMyGroups/ywmGroupsMyGroups"
                    }));
                }
            });
        },
        openTeam: function() {
            var t = this;
            if (0 == this.data.popStock || this.data.goodsCount > this.data.popStock) return wx.showToast({
                title: "库存不足",
                icon: "none",
                duration: 2500
            }), void this.setData({
                goodsCount: this.data.popStock
            });
            if (0 != this.data.optionsMaxCount && this.data.goodsCount > this.data.optionsMaxCount) return wx.showToast({
                title: "抱歉，该商品限购".concat(this.data.optionsMaxCount, "件"),
                icon: "none",
                duration: 2500
            }), void this.setData({
                goodsCount: this.data.optionsMaxCount
            });
            if (this.data.goodsCount < 0) return wx.showToast({
                title: "商品数量不能小于0",
                icon: "none",
                duration: 2500
            }), void this.setData({
                goodsCount: 1
            });
            if (i._isTextEmpty(this.data.groupModel)) wx.showToast({
                title: "请选择开团点",
                icon: "none",
                duration: 2500
            }); else {
                var o = [];
                o.push(t.data.goodsId);
                var a = i.getNetAddresss("from.div-from.isDisplay");
                a += "&goods_ids=" + JSON.stringify(o), i._getNetWork({
                    showToastIn: !1,
                    url: a,
                    success: function(o) {
                        var a = o.data;
                        if (1 == a.result) {
                            var s = a.data;
                            if (console.log("xxxx", s), a.data.status && !a.data.member_status) wx.showModal({
                                title: "提示",
                                content: "购买此商品,请补充您的个人信息",
                                success: function(o) {
                                    o.confirm ? (wx.navigateTo({
                                        url: "/packageB/member/address/myinfo/myinfo?tag=group&activityId=" + t.data.activityId
                                    }), t.triggerEvent("popupModeshowChild", !0), t.setData({
                                        popupSpecs: !1,
                                        popupSpecs2: !1
                                    })) : o.cancel && console.log("用户点击取消");
                                }
                            }); else {
                                var i = 0;
                                t.properties.store_id && null != t.properties.store_id && 0 != t.properties.store_id && (i = t.properties.store_id);
                                var e = "/packageD/buy/myOrder_v2/myOrder_v2?tag=-2&goodsId=" + t.data.goodsId + "&optionsId=" + t.data.optionsId + "&total=" + t.data.goodsCount + "&level_id=" + t.data.groupModel + "&option_level_id=" + t.data.option_level_id;
                                i && (e = e + "&groupStoreID=" + i), "ywmGroup" == t.data.goodsType && (e += "&plu=ywm"), 
                                wx.navigateTo({
                                    url: e
                                }), t.triggerEvent("popupModeshowChild", !0), t.setData({
                                    popupSpecs: !1,
                                    popupSpecs2: !1
                                });
                            }
                        } else wx.showToast({
                            icon: "none",
                            title: a.msg,
                            duration: 2500
                        });
                    },
                    fail: function(t) {}
                });
            }
        },
        setGroupInfo: function(t) {
            if (this.data.gooddatas && this.data.gooddatas.has_many_options) for (var o = 0; o < this.data.gooddatas.has_many_options.length; o++) {
                if (this.data.gooddatas.has_many_options[o].option_id == this.data.optionsId) return this.setData({
                    selectGroupInfo: this.data.gooddatas.has_many_options[o].has_many_option_level
                }), this.data.optionsMaxCount = 0 == this.data.gooddatas.has_many_options[o].buy_limit ? this.data.gooddatas.has_many_options[0].stock : this.data.gooddatas.has_many_options[0].buy_limit, 
                this.setData({
                    popStock: this.data.gooddatas.has_many_options[o].stock
                }), void this.selectGroup();
            }
        },
        checkActivity: function() {
            var t = this, o = this, a = null;
            0 != this.data.popPrice ? (a = i.getNetAddresss("plugin.snatch-regiment.api.index.getSnatchData"), 
            a += "&at_id=" + this.data.activityId + "&art=inspectOverrun&option_id=" + this.data.optionsId + "&goods_id=" + this.data.goodsId + "&total=" + this.data.goodsCount, 
            i._getNetWork({
                url: a,
                success: function(a) {
                    var s = a.data;
                    1 == s.result ? (t.setData({
                        isCheckActivity: !0
                    }), console.log(t.data.isAward, "456"), "grabGroup" == t.data.goodsType && 1 == t.data.isAward ? (console.log("团长开团不参与中奖"), 
                    wx.showModal({
                        title: "提示",
                        content: "开团后不参与中奖？",
                        success: function(t) {
                            t.confirm ? (o.popupSpecsbtn(), o.OpenLeader()) : t.cancel && wx.showToast({
                                icon: "none",
                                title: "已取消",
                                duration: 2500
                            });
                        }
                    })) : "grabGroup" == t.data.goodsType && 2 == t.data.isAward && t.submitActionQt()) : (t.setData({
                        isCheckActivity: !1
                    }), wx.showToast({
                        icon: "none",
                        title: s.msg,
                        duration: 2500
                    }));
                }
            })) : wx.showModal({
                title: "提示",
                showCancel: !1,
                content: "开团/参团金额不正确，不能为0",
                success: function(t) {}
            });
        },
        OpenLeader: function() {
            var t = i.getNetAddresss("plugin.snatch-regiment.api.team.OpenLeader");
            t += "&at_id=" + this.data.activityId + "&goods_id=" + this.data.goodsId, i._getNetWork({
                url: t,
                success: function(t) {
                    var o = t.data;
                    1 == o.result ? (wx.showToast({
                        icon: "none",
                        title: "开团成功!",
                        duration: 2500
                    }), wx.navigateTo({
                        url: "/packageE/grab_group/grab_group_my/grab_group_my"
                    })) : wx.showToast({
                        icon: "none",
                        title: o.msg,
                        duration: 2500
                    });
                }
            });
        },
        submitActionQt: function() {
            var t = this.data.goodsId, o = this.data.optionsId, a = this.data.goodsCount;
            if (0 != this.data.optionsMaxCount) if (a <= 0) wx.showToast({
                icon: "none",
                title: "请选择商品数量",
                duration: 2500
            }); else {
                var s = this, e = [];
                e.push(t);
                var n = i.getNetAddresss("from.div-from.isDisplay");
                n += "&goods_ids=" + JSON.stringify(e), i._getNetWork({
                    showToastIn: !1,
                    url: n,
                    success: function(i) {
                        var e = i.data;
                        1 == e.result ? e.data.status && !e.data.member_status ? wx.showModal({
                            title: "提示",
                            content: "购买此商品,请补充您的个人信息",
                            success: function(t) {
                                t.confirm ? wx.navigateTo({
                                    url: "/packageB/member/address/myinfo/myinfo?tag=delta"
                                }) : t.cancel && console.log("用户点击取消");
                            }
                        }) : wx.navigateTo({
                            url: "/packageD/buy/myOrder_v2/myOrder_v2?tag=-2&optionsId=" + o + "&goodsId=" + t + "&total=" + a + "&type=grabGroup_open&at_id=" + s.data.activityId
                        }) : wx.showToast({
                            icon: "none",
                            title: e.msg,
                            duration: 2500
                        });
                    },
                    fail: function(t) {}
                });
            } else wx.showToast({
                icon: "none",
                title: "商品库存不足",
                duration: 2500
            });
        },
        buyNowRequestRetailGood: function(t, o, a) {
            if (0 != this.data.optionsMaxCount) if (a <= 0) wx.showToast({
                icon: "none",
                title: "请选择商品数量",
                duration: 2500
            }); else if (1 == this.data.goodsInfo.has_option && i._isTextEmpty(o)) wx.showToast({
                icon: "none",
                title: "请选择规格！",
                duration: 2500
            }); else if (0 != this.data.popPrice) if (2 != this.data.mode || 0 != this.data.levelModel) {
                var s = "/packageD/buy/myOrder_v2/myOrder_v2?tag=newRetail", e = null;
                if (console.log(this.data.buyType, "asdasd"), 3 == this.data.mode && 2 == this.data.buyType) e = 4; else {
                    if (2 == this.data.mode && 2 == this.data.buyType) return e = 1, void wx.navigateTo({
                        url: s + "&goodsId=" + t + "&optionsId=" + o + "&total=" + a + "&retailState=" + e + "&NRLevelId=" + this.data.levelModel
                    });
                    if (1 == this.data.mode && 2 == this.data.buyType) e = 0; else if (2 == this.data.mode && 1 == this.data.buyType) return e = 5, 
                    void this.agentSales(o, a);
                }
                wx.navigateTo({
                    url: s + "&goodsId=" + t + "&optionsId=" + o + "&total=" + a + "&retailState=" + e
                });
            } else wx.showToast({
                icon: "none",
                title: "请选择等级套餐！",
                duration: 2500
            }); else wx.showToast({
                icon: "none",
                title: "价格设置有误，请联系客服！",
                duration: 2500
            }); else wx.showToast({
                icon: "none",
                title: "商品库存不足",
                duration: 2500
            });
        },
        agentSales: function(t, o) {
            var a = this, s = i.getNetAddresss("plugin.new-retail.frontend.index.agentSales");
            i._postNetWork({
                url: s,
                data: {
                    goods_id: this.data.goodsId,
                    goods_option: t,
                    goods_num: o,
                    level_id: this.data.levelModel,
                    goods_name: this.data.goodsInfo.title
                },
                success: function(t) {
                    var o = t.data;
                    a.popupSpecsbtn(), 1 == o.result ? wx.navigateTo({
                        url: "/packageH/newRetail/newRetail_agencyPackage/newRetail_agencyPackage?id=" + o.data.id
                    }) : wx.showToast({
                        title: o.msg,
                        duration: 2500,
                        icon: "none"
                    });
                },
                fail: function(t) {
                    wx.hideLoading(), console.log(t.msg);
                }
            });
        },
        clickLevelModel: function(t) {
            var o = t.currentTarget.dataset.item;
            this.setData({
                popPrice: o.level_unit_total_price,
                goodsCount: o.level_num,
                levelModel: o.level_id
            });
        },
        buyNowRequestZhpGroup: function(t, o, a) {
            this.hidePopView2();
            var s = this.data.gooddatas.id;
            this.triggerEvent("popupModeshowChild", !0), 0 == o || "" == o ? this.setData({
                popupSpecs2: !1
            }) : this.setData({
                popupSpecs: !1
            }), wx.navigateTo({
                url: "/packageD/buy/myOrder_v2/myOrder_v2?tag=zhpGroup&goodsId=" + t + "&optionsId=" + o + "&total=" + a + "&activity_id=" + s
            });
        },
        setZhpGroupInfo: function(t) {
            if (this.data.gooddatas && this.data.gooddatas.has_many_options) for (var o = 0; o < this.data.gooddatas.has_many_options.length; o++) {
                this.data.gooddatas.has_many_options[o].option_id == this.data.optionsId && (this.data.optionsMaxCount = 0 == this.data.gooddatas.has_many_options[o].buy_limit ? this.data.gooddatas.has_many_options[0].stock : this.data.gooddatas.has_many_options[0].buy_limit, 
                this.setData({
                    popStock: this.data.gooddatas.has_many_options[o].stock,
                    popPrice: this.data.gooddatas.has_many_options[o].group_price
                }));
            }
        }
    }
});